﻿using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using NHibernate;
using Salary.Api;
using Salary.Data;
using Salary.Domain;
using Salary.Domain.Repository;
using Salary.NHibernate;
using Salary.Services;

namespace Salary.Installer
{
    public class CoreInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Component.For(typeof(IRepository<>)).ImplementedBy(typeof(NhRepository<>)));
            container.Register(Component.For<NhInterceptor>());
            container.Register(Classes.FromThisAssembly().InSameNamespaceAs<SalaryApi>().Configure(c => c.Interceptors<NhInterceptor>()));
            container.Register(Classes.FromThisAssembly().InSameNamespaceAs<AwardService>().Configure(c => c.Interceptors<NhInterceptor>()));
            container.Register(Component.For<NhConfigurator>());
            container.Register(
            Component.For<ISessionFactory>().UsingFactoryMethod(NhConfigurator.InitializeSessionFactory));
        }
    }
}